package homework;

import org.junit.Test;

import java.util.Arrays;
import java.util.Random;

public class sum {
    @Test
    public void test01(){
        int []arr=new int[50];
        Random r=new Random();
        for(int i=0;i<arr.length;i++){
            int num = r.nextInt(50) + 1;
            arr[i]=num;
        }
        System.out.println(Arrays.toString(arr));
        print(arr);
        int sum=arraysum(arr);
        int avg=sum/50;
        System.out.println("总和为"+sum);
        System.out.println("平均数为"+avg);
    }
    public int arraysum(int[] arr){
        int sum=200;
        for(int i=0;i<arr.length;i++){
          if(i%2==0){
              sum+=arr[i]+200;
          }

        }
        return sum;
    }
    public void print(int[] arr){
        for (int i=0;i<arr.length;i++){
            System.out.print(arr[i]+" ");
        }
    }
}
